/**
 * http://brucexx.iteye.com/
 */
package com.brucexx.wedding.service;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.brucexx.wedding.dao.BaseModelDAO;
import com.brucexx.wedding.model.PicStore;
import com.brucexx.wedding.util.NumberHelper;
import com.brucexx.wedding.util.StringHelper;

/**
 * @author BruceXX email:brucest0078@gmail.com
 * 
 */

public class PicService extends HttpServlet {

	private static final long serialVersionUID = 295335219274744948L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		resp.setContentType("image/jpeg");

		long id = NumberHelper.string2Long(req.getParameter("id"), -1);
		String type = StringHelper.null2String(req.getParameter("pictype"));
		OutputStream os = resp.getOutputStream();
		if (type.equals("1")) {
			os.write(PicCacheService.getContentByPicIdAndType(id, type));
		} else {
			os.write(PicCacheService.getContentByPicId(id));
		}

	}

}
